export default {
  common: {
    baseUrl: "http://admin.cn/index.php/index/",
    data: {},
    header: {
      "Content-Type": "application/json",
      "Content-Type": "application/x-www-form-urlencoded",
    },
    method: "GET",
    dataType: "json",
  },
  request(option = {}) {
    option.url = option.url.search("http") == 0 ? option.url : this.common.baseUrl + option.url;
    // option.url = this.common.baseUrl + option.url;
    option.data = option.data || this.common.data;
    option.header = option.header || this.common.header;
    option.method = option.method || this.common.method;
    option.dataType = option.dataType || this.common.dataType;
    return new Promise((res, rej) => {
      uni.showLoading({
        title: "加载中",
      });
      uni.request({
        ...option,
        success: (result) => {
          // console.log(re);
          if (result.data.resultCode != 200) {
            setTimeout(function () {
              uni.hideLoading();
            }, 300);
          }
          setTimeout(function () {
            uni.hideLoading();
          }, 300);
          res(result.data);
        },
        fail: (result) => {
          setTimeout(function () {
            uni.hideLoading();
          }, 300);
          uni.showLoading({
            title: "连接服务器失败",
          });
        },
        complete: () => {},
      });
    });
  },
};
